import { store } from "@/app/store";
import { message } from "antd";
import axios from "axios";

const request = axios.create({
    baseURL:process.env.REACT_APP_HOS_API,
    timeout:10000,
});

request.interceptors.request.use((config)=>{
    const token = store.getState().user.token;
    
    
    if(token){
       ( config.headers as any).token = token;
    }
    return config
})

request.interceptors.response.use((response)=>{
    if(response.data.code === 200){
        return response.data.data;
    }else{
        message.error(response.data.message);
        return Promise.reject(response.data.message);
    }
},(error)=>{
    message.error(error);
    return Promise.reject(error);
})

export default request;